//
//  CommonTableViewCell.swift
//  koolcar
//
//  Created by kuaimaxiansheng on 2023/10/20.
//

import UIKit

class CommonTableViewCell: UITableViewCell {
    var bgView: UIView!
    var bgLayer1: CALayer!
    var leftImageView: UIImageView!
    var titleLab: UILabel!
    var contentLab: UILabel!
    var rightImageView: UIImageView!
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.backgroundColor = .white
        self.clipsToBounds = true
        
        self.initUI()
        
    }
    
    func initUI(){
        
        self.bgView = UIView(frame: .zero)
        self.bgView.backgroundColor = .white
        // fillCode
        bgLayer1 = CALayer()
        bgLayer1.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 1).cgColor
        bgView.layer.addSublayer(bgLayer1)
        // shadowCode
        bgView.layer.shadowColor = UIColor(red: 0.96, green: 0.96, blue: 0.98, alpha: 0.9).cgColor
        bgView.layer.shadowOffset = CGSize(width: 0, height: 0)
        bgView.layer.shadowOpacity = 0.89
        bgView.layer.shadowRadius = 10
        self.contentView.addSubview(bgView)
        
        self.leftImageView = UIImageView(frame: .zero)
        self.bgView.addSubview(leftImageView)
        
        self.titleLab = UILabel(frame: .zero)
        self.titleLab.textColor = Theme.titleLabColor
        self.titleLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        self.bgView.addSubview(self.titleLab)
        
        self.contentLab = UILabel(frame: .zero)
        self.contentLab.textColor = Theme.titleLabColor
        self.contentLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        self.bgView.addSubview(self.contentLab)
        
        self.rightImageView = UIImageView(frame: .zero)
        self.bgView.addSubview(rightImageView)
        
        self.addLayout()
    }
    
    func addLayout(){
        self.bgView.snp.makeConstraints { make in
            make.top.equalTo(5)
            make.left.equalTo(14)
            make.right.equalTo(-14)
            make.height.equalTo(44)
            make.bottom.equalTo(-10)
        }
        bgLayer1.frame = self.bgView.bounds
        
        
        self.leftImageView.snp.makeConstraints { make in
            make.centerY.equalTo(self.bgView.snp.centerY)
            make.left.equalTo(10)
            make.width.height.equalTo(14)
        }
        
        self.titleLab.snp.makeConstraints { make in
            make.centerY.equalTo(self.bgView.snp.centerY)
            make.left.equalTo(self.leftImageView.snp.right).offset(3)
            make.height.equalTo(44)
        }
        
        self.contentLab.snp.makeConstraints { make in
            make.centerY.equalTo(self.bgView.snp.centerY)
            make.right.equalTo(-27)
            make.height.equalTo(44)
        }
        
        self.rightImageView.snp.makeConstraints { make in
            make.centerY.equalTo(self.bgView.snp.centerY)
            make.right.equalTo(-10)
            make.width.equalTo(5)
            make.height.equalTo(8)
        }
    }
    
    
    func updateRightImage(){
        self.rightImageView.snp.updateConstraints{ make in
            make.width.equalTo(14)
            make.height.equalTo(14)
        }
        self.updateConstraints()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
